package com.wang.dao;

import com.wang.entity.User;
import com.wang.util.JdbcUtil;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;

/**
 * 注册dao
 */
public class AddUser {
    private JdbcUtil util = new JdbcUtil();
    public int addUser(User user){
        String sql = "insert into user(username,password,auth) values(?,?,?)";
        PreparedStatement ps = util.createStatement(sql);
        int result = 0;
        try {
            ps.setString(1,user.getName());
            ps.setString(2,user.getPassword());
            ps.setInt(3,user.getAuth());
            result = ps.executeUpdate();
        } catch (SQLException e) {
            e.printStackTrace();
        } finally {
            util.close();
        }
        return result;
    }

}
